package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.GoodsDetailOrder;
import com.szgr.baoyin.utils.Constant;
import com.szgr.baoyin.utils.MyTool;

import java.util.List;

/**
 * Created by yang on 16/1/19.
 */
public class GoodsDetailOrderListAdapter extends BaseAdapter {
    private List<GoodsDetailOrder.ExtendOrderGoodsEntity> data;
    private Context mContext;
    public GoodsDetailOrderListAdapter(Context context,List<GoodsDetailOrder.ExtendOrderGoodsEntity> data){
        mContext = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_new_store_list_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();

        GoodsDetailOrder.ExtendOrderGoodsEntity eog = data.get(position);
        MyTool.showPicture(mContext, holder.img_head, Constant.URL_IMAGE + eog.getGoods_image());
        holder.tv_title.setText(eog.getGoods_name());
        holder.tv_price.setText("¥" + eog.getGoods_price() + "元");
        holder.tv_count.setVisibility(View.VISIBLE);
        holder.tv_count.setText("X" + eog.getGoods_num());
//        holder.tv_post.setText(eog.getGoods_jingle());
        holder.tv_post.setTextColor(0xfff08200);

//        holder.img_bao.setVisibility(View.GONE);
//        holder.img_hongbao.setVisibility(View.GONE);
//        holder.img_dubi.setVisibility(View.GONE);
        holder.tv_place.setVisibility(View.GONE);
        holder.tv_log.setVisibility(View.GONE);

        return convertView;
    }

    public void setData(List<GoodsDetailOrder.ExtendOrderGoodsEntity> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    private class ViewHolder {
        ImageView img_head;
        TextView tv_title;
        //        ImageView img_bao;
//        ImageView img_hongbao;
//        ImageView img_dubi;
        TextView tv_log;
        TextView tv_place;
        TextView tv_post;
        TextView tv_price; //价格
        TextView tv_count; //多少人付款

        public ViewHolder(View view){
            img_head = (ImageView) view.findViewById(R.id.store_item_icon);
            tv_title = (TextView) view.findViewById(R.id.store_item_title);
//            img_bao = (ImageView) view.findViewById(R.id.store_item_bao);
//            img_hongbao = (ImageView) view.findViewById(R.id.store_item_hongbao);
//            img_dubi = (ImageView) view.findViewById(R.id.store_item_dubi);
            tv_place = (TextView) view.findViewById(R.id.store_item_place);
            tv_log = (TextView) view.findViewById(R.id.fuk_android);
            tv_post = (TextView) view.findViewById(R.id.store_item_post_price);
            tv_price = (TextView) view.findViewById(R.id.store_item_price);
            tv_count = (TextView) view.findViewById(R.id.store_item_num);
        }
    }
}
